package com.dferreira.axil.data;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import com.dferreira.axil.model.Vendedor;

@RequestScoped
public class ListaDeVendedores {

    @Inject
    private RepositorioDeVendedores repositorioDeVendedores;

    private List<Vendedor> vendedores;

    @Produces
    @Named
    public List<Vendedor> getVendedores() {
        return vendedores;
    }

    public void quandoAlterarListaDeVendedores(@Observes(notifyObserver = Reception.IF_EXISTS) final Vendedor vendedor) {
    	recuperarVendedores();
    }

    @PostConstruct
    public void recuperarVendedores() {
        vendedores = repositorioDeVendedores.findAllOrderedByName();
    }
}
